package cn.iocoder.yudao.module.biz.controller.admin.risk.riskWarningSignCategory;

import cn.iocoder.yudao.module.biz.controller.admin.risk.riskWarningSignCategory.vo.*;
import cn.iocoder.yudao.module.biz.convert.risk.riskWarningSignCategory.BizRiskWarningSignCategoryConvert;
//import cn.iocoder.yudao.module.biz.convert.risk.riskWarningSignCategory.BizRiskWarningSignCategoryConvertImpl;
import cn.iocoder.yudao.module.biz.dal.dataobject.risk.riskWarningSignCategory.BizRiskWarningSignCategoryDO;
import cn.iocoder.yudao.module.biz.service.risk.riskWarningSignCategory.BizRiskWarningSignCategoryService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

@Api(tags = "管理后台 - 警示标志类别")
@RestController
@RequestMapping("/biz/risk-warning-sign-category")
@Validated
public class BizRiskWarningSignCategoryController {

    @Resource
    private BizRiskWarningSignCategoryService riskWarningSignCategoryService;

    @PostMapping("/create")
    @ApiOperation("创建警示标志类别")
    @PreAuthorize("@ss.hasPermission('biz:risk-warning-sign-category:create')")
    public CommonResult<String> createRiskWarningSignCategory(@Valid @RequestBody BizRiskWarningSignCategoryCreateReqVO createReqVO) {
        return success(riskWarningSignCategoryService.createRiskWarningSignCategory(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新警示标志类别")
    @PreAuthorize("@ss.hasPermission('biz:risk-warning-sign-category:update')")
    public CommonResult<Boolean> updateRiskWarningSignCategory(@Valid @RequestBody BizRiskWarningSignCategoryUpdateReqVO updateReqVO) {
        riskWarningSignCategoryService.updateRiskWarningSignCategory(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除警示标志类别")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:risk-warning-sign-category:delete')")
    public CommonResult<Boolean> deleteRiskWarningSignCategory(@RequestParam("id") String id) {
        riskWarningSignCategoryService.deleteRiskWarningSignCategory(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得警示标志类别")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:risk-warning-sign-category:query')")
    public CommonResult<BizRiskWarningSignCategoryRespVO> getRiskWarningSignCategory(@RequestParam("id") String id) {
        BizRiskWarningSignCategoryDO riskWarningSignCategory = riskWarningSignCategoryService.getRiskWarningSignCategory(id);
        return success(BizRiskWarningSignCategoryConvert.INSTANCE.convert(riskWarningSignCategory));
    }

    @GetMapping("/list")
    @ApiOperation("获得警示标志类别列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:risk-warning-sign-category:query')")
    public CommonResult<List<BizRiskWarningSignCategoryRespVO>> getRiskWarningSignCategoryList(@RequestParam("ids") Collection<String> ids) {
        List<BizRiskWarningSignCategoryDO> list = riskWarningSignCategoryService.getRiskWarningSignCategoryList(ids);
        return success(BizRiskWarningSignCategoryConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得警示标志类别分页")
    @PreAuthorize("@ss.hasPermission('biz:risk-warning-sign-category:query')")
    public CommonResult<PageResult<BizRiskWarningSignCategoryRespVO>> getRiskWarningSignCategoryPage(@Valid BizRiskWarningSignCategoryPageReqVO pageVO) {
        PageResult<BizRiskWarningSignCategoryDO> pageResult = riskWarningSignCategoryService.getRiskWarningSignCategoryPage(pageVO);
        return success(BizRiskWarningSignCategoryConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/getAllList")
    @ApiOperation("获得警示标志类别不分页")
    @PreAuthorize("@ss.hasPermission('biz:risk-warning-sign-category:query')")
    public CommonResult<List<BizRiskWarningSignCategoryRespVO>> getRiskWarningSignCategory() {
        List<BizRiskWarningSignCategoryDO> list = riskWarningSignCategoryService.getRiskWarningSignCategoryList();
        return success(BizRiskWarningSignCategoryConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出警示标志类别 Excel")
    @PreAuthorize("@ss.hasPermission('biz:risk-warning-sign-category:export')")
    @OperateLog(type = EXPORT)
    public void exportRiskWarningSignCategoryExcel(@Valid BizRiskWarningSignCategoryExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizRiskWarningSignCategoryDO> list = riskWarningSignCategoryService.getRiskWarningSignCategoryList(exportReqVO);
        // 导出 Excel
        List<BizRiskWarningSignCategoryExcelVO> datas = BizRiskWarningSignCategoryConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "警示标志类别.xls", "数据", BizRiskWarningSignCategoryExcelVO.class, datas);
    }

}
